//
//  MKMainViewController.m
//  singForYou
//
//  Created by nicolas on 2016/12/7.
//  Copyright © 2016年 nicolas. All rights reserved.
//

#import "MKMainViewController.h"

#import <Masonry.h>
#import <MJExtension/MJExtension.h>


@interface MKMainViewController ()
//背景图片
@property (strong, nonatomic) UIImageView *bgImageView;
//歌名
@property (strong, nonatomic) UILabel *songNameLbl;
//歌手
@property (strong, nonatomic) UILabel *singerLbl;
//歌手图片
@property (strong, nonatomic) UIImageView *singerInfosImageView;
//歌词
@property (strong, nonatomic) UILabel *lyricsLbl;
//歌词信息
@property (strong, nonatomic) UILabel *infoLbl;
//左侧时间
@property (strong, nonatomic) UILabel *leftTimeLbl;
//右侧时间
@property (strong, nonatomic) UILabel *rightTimeLbl;
//进度条
@property (strong, nonatomic) UISlider *progressSlider;
//上一首歌
@property (strong, nonatomic) UIButton *previousBtn;
//播放
@property (strong, nonatomic) UIButton *playBtn;
//下一首歌
@property (strong, nonatomic) UIButton *nextBtn;

@end

@implementation MKMainViewController

#pragma mark - Life circle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self prepareUI];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.singerInfosImageView.layer.cornerRadius = self.singerInfosImageView.bounds.size.width * 0.5;
}

#pragma mark - Private methods
//制作模糊背景
- (void)makeBlurEffect {
    // UIBlurEffect表示模糊效果
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    //  效果视图, 得到效果对应的View
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    [self.bgImageView addSubview:effectView];
    
    // 添加约束
    [effectView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];

}
//初始化控件
- (void)prepareUI {
    
    //背景图片
    UIImageView *bgImageView = [[UIImageView alloc] init];
    [self.view addSubview:bgImageView];
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.top.equalTo(self.view);
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
    }];
    self.bgImageView = bgImageView;
    
    //歌名
    UILabel *songNameLbl = [[UILabel alloc] init];
    songNameLbl.text= @"一首简单的歌";
    songNameLbl.textAlignment = NSTextAlignmentCenter;
    songNameLbl.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:songNameLbl];
    [songNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
        make.top.equalTo(self.view).offset(40);
        make.height.mas_equalTo(40);
    }];
    self.songNameLbl = songNameLbl;
    //歌手
    UILabel *singerLbl = [[UILabel alloc] init];
    singerLbl.text= @"王力宏";
    singerLbl.textAlignment = NSTextAlignmentCenter;
    singerLbl.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:singerLbl];
    [singerLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(20);
        make.right.equalTo(self.view.mas_right).offset(-20);
        make.top.equalTo(songNameLbl.mas_bottom).offset(60);
        make.height.mas_equalTo(40);
    }];
    self.singerLbl = singerLbl;
    //图片
    UIImageView *singerInfosImageView = [[UIImageView alloc] init];
    singerInfosImageView.image = [UIImage imageNamed:@"blue"];
    [self.view addSubview:singerInfosImageView];
    [singerInfosImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(60);
        make.right.equalTo(self.view).offset(-60);
        make.top.equalTo(singerLbl.mas_bottom).offset(40);
        make.height.mas_equalTo(160);
    }];
    self.singerInfosImageView = singerInfosImageView;
    //歌词
    UILabel *lyricsLbl = [[UILabel alloc] init];
    lyricsLbl.text = @"乌黑的发尾盘成一个圈";
    lyricsLbl.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:lyricsLbl];
    [lyricsLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
        make.top.equalTo(singerInfosImageView.mas_bottom).offset(30);
        make.height.mas_equalTo(40);
    }];
    self.lyricsLbl = lyricsLbl;
    //信息
    UILabel *infoLbl = [[UILabel alloc] init];
    infoLbl.text = @"爱情转移";
    infoLbl.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:infoLbl];
    [infoLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(15);
        make.top.equalTo(lyricsLbl.mas_bottom).offset(45);
        make.height.mas_equalTo(40);
    }];
    self.infoLbl = infoLbl;
    //左侧歌曲时间
    UILabel *leftTimeLbl = [[UILabel alloc] init];
    leftTimeLbl.text = @"00:00";
    leftTimeLbl.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:leftTimeLbl];
    [leftTimeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(15);
        make.top.equalTo(infoLbl.mas_bottom);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(40);
    }];
    self.leftTimeLbl = leftTimeLbl;
    //歌曲时长
    UILabel *rightTimeLbl = [[UILabel alloc] init];
    rightTimeLbl.text = @"03:00";
    rightTimeLbl.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:rightTimeLbl];
    [rightTimeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(-15);
        make.top.equalTo(infoLbl.mas_bottom);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(40);
    }];
    self.rightTimeLbl = rightTimeLbl;
    //进度条
    UISlider *progressSlider = [[UISlider alloc] init];
    progressSlider.thumbTintColor = [UIColor greenColor];
    progressSlider.minimumTrackTintColor = [UIColor greenColor];
    progressSlider.maximumTrackTintColor = [UIColor grayColor];
    [self.view addSubview:progressSlider];
    [progressSlider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftTimeLbl.mas_right).offset(2);
        make.top.equalTo(infoLbl.mas_bottom);
        make.right.equalTo(rightTimeLbl.mas_left).offset(-4);
        make.height.mas_equalTo(40);
    }];
    self.progressSlider = progressSlider;
    //上一首歌
    UIButton *previousBtn = [[UIButton alloc] init];
    [previousBtn setBackgroundImage:[UIImage imageNamed:@"player_btn_pre_normal"] forState:UIControlStateNormal];
    [previousBtn setBackgroundImage:[UIImage imageNamed:@"player_btn_pre_highlight" ]forState:UIControlStateHighlighted];
    [self.view addSubview:previousBtn];
    [previousBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(75);
        make.bottom.equalTo(self.view).offset(-15);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
    }];
    self.previousBtn = previousBtn;
    //播放
    UIButton *playBtn = [[UIButton alloc] init];
    [playBtn setBackgroundImage:[UIImage imageNamed:@"player_btn_play_normal"] forState:UIControlStateNormal];
    [playBtn setBackgroundImage:[UIImage imageNamed:@"player_btn_play_highlight"] forState:UIControlStateHighlighted];
    [playBtn setBackgroundImage:[UIImage imageNamed:@"player_btn_pause_normal"] forState:UIControlStateSelected];
    [self.view addSubview:playBtn];
    [playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(previousBtn.mas_right).offset(20);
        make.bottom.equalTo(previousBtn);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(70);
    }];
    self.playBtn = playBtn;
    //下一首歌
    UIButton *nextBtn = [[UIButton alloc] init];
    [nextBtn setBackgroundImage:[UIImage imageNamed:@"player_btn_next_normal"] forState:UIControlStateNormal];
    [nextBtn setBackgroundImage:[UIImage imageNamed:@"player_btn_next_highlight"] forState:UIControlStateHighlighted];
    [self.view addSubview:nextBtn];
    [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(playBtn.mas_right).offset(20);
        make.bottom.equalTo(previousBtn);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
    }];
    self.nextBtn = nextBtn;
    
}

//上下震动换歌
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    
    if (motion == UIEventSubtypeMotionShake) {
        //下一首歌
    }
    
}


@end
